<template>
	<view class="changePhone">
		<comHead :title="$t('grzx.xgsjh')" :isLeft="true" :isRight="false"></comHead>
		<view class="text">
			<text>{{$t('grzx.yzsjh')}}</text>
			<!-- <text v-if="isSend">{{$t('grzx.yzmyfszhj')}}</text> -->
			<text v-if="isSend">{{$t('grzx.yzmyfs')}}</text>
			<text v-else >{{mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')}}</text>
		</view>
		<view class="inputBox">
			<input v-model="captcha" type="text" :placeholder="$t('grzx.qsryzm')" />
			<text @click="sendCaptcha">{{$t('grzx.fsyzm')}}</text>
		</view>
		<view class="btn" @click="toChangeMobile">
			<text>{{$t('grzx.xgsjh')}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isSend: false,
				captcha: '',
				mobile: '',
			}
		},
		onLoad() {
			this.getMobile()
		},
		methods: {
			async getMobile() {
				const res = await this.$myRequest({
					url: 'api/user/index',
					method: 'GET'
				})
				if (res.code == 1) {
					this.mobile = res.data.mobile
				}
			},
			async sendCaptcha() {
				const res = await this.$myRequest({
					url: 'api/sms/send',
					data: {
						mobile: this.mobile,
						event: 'changemobile',
					}
				});
				console.log(res);
				if(res.code == 1){
					this.isSend = true;
				}
			},
			async toChangeMobile(){
				if(!this.isSend) return;
				if(this.captcha !== ''){
					if(this.captcha === '1234'){
						this.comLink('/pages/changePhone2');
					}
				}else{
						this.$tools.showTx(this.$t('grzx.qsryzm'))
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.changePhone {
		height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;

		.text {
			width: 100%;
			padding: 50rpx;
			box-sizing: border-box;
			color: rgba(255, 255, 255, .8);
			font-size: 34rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			text {
				&:nth-child(2) {
					color: #aaa;
					font-size: 28rpx;
					margin-right: 20rpx;
				}
			}
		}

		.inputBox {
			width: 650rpx;
			height: 80rpx;
			// background: rgba(#000, 0.3);
			display: flex;
			align-items: center;
			justify-content: space-between;
			color: #5888FF;
			font-size: 26rpx;
			padding: 0 30rpx 0 0;
			box-sizing: border-box;
			border-radius: 60rpx;

			input {
				color: #aaa;
				font-size: 26rpx;
				width: 360rpx;
				height: 80rpx;
				padding-left: 30rpx;
				border-radius: 40rpx;
				background-color: rgba(0, 0, 0, .5);
			}

			text {
				color: #fff;
				border-bottom: 2rpx solid #fff;
			}
		}

		.btn {
			width: 650rpx;
			height: 80rpx;
			background: linear-gradient(270deg, #5F58FD 0%, #62B6FC 100%);
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 60rpx;
			color: #fff;
			font-size: 30rpx;
			margin-top: 100rpx;
		}
	}
</style>